dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.layout.ContentPane");
var UAMROLE={
	handleOnChangePopulate:function(){
		var roleTypeId = document.getElementsByName("roleType").item(0).value;
		
		var filteringSelect = dijit.byId('filteringSelect');
		
		if(roleTypeId != "" && filteringSelect != "")
			{
			var ajaxUrl = getAppName() + "/uamroles/populateRoleSubType/"
					+ roleTypeId;
			var contentId = "main";
			var _targetNode = dojo.byId(contentId);
			var xhrArgs = {
				url : ajaxUrl,
				handleAs : "json",
				load : function(data) {
					UAMROLE.populateRoleSubType(data);
				},
				error : function(error) {
					_targetNode.innerHTML = "An unexpected error occurred: "
							+ error;
				}
			};
			dojo.xhrGet(xhrArgs);
			}
	},
	populateRoleSubType:function(jsonRoleSubType){
		var stateStore = new dojo.data.ItemFileReadStore({
			data:jsonRoleSubType
        });		
        var filteringSelect = dijit.byId('_roleSubType_id');
        filteringSelect.setValue("");
        filteringSelect.store = stateStore;
		 stateStore.fetch();        
	}
};
var UAMUSER = {
		populateProfile:function(){
			var cbIsAdmin = dojo.byId('_IsAdmin_id');			
			var cbvalue = cbIsAdmin.checked;			
			var ajaxUrl = getAppName()+"/uamusers/populateprofileadmin/"+cbvalue;
			var xhrArgs = {
		          url: ajaxUrl,
		          handleAs:"json",
		          load: function(data) {		        	  
		        	  UAMUSER.populateProfileFill(data);
		          },
		          error: function(error) {
		        	  alert(error);
		          }
		      };
		      dojo.xhrGet(xhrArgs);		      
		},
		populateProfileFill:function(jsonProfile){
			var stateStore = new dojo.data.ItemFileReadStore({
				data:jsonProfile
	        });			
			var filteringSelect = dijit.byId('_profile.id_id');
	       filteringSelect.setValue("");
	        filteringSelect.store = stateStore;
			 stateStore.fetch();			
		}
};
var COMBINATIONMATRIX = {
    handleOnChangeCombinationType : function() {
        var combinationType = dijit.byId('_combinationType_id');
        if (combinationType == "CASE") {
            dijit.byId("_documentType_id").attr("disabled", true);
            dijit.byId("_processingCentre_id").attr("required", true);
            dijit.byId("_transactionType_id").attr("required", true);
            dijit.byId("_country_id").attr("required", true);
            dijit.byId("_documentType_id").attr("required", false);
            dijit.byId("_productType_id").attr("required", false);
            dijit.byId("_userLocation_id").attr("required", false);
        } else {
            dijit.byId("_documentType_id").attr("disabled", false);
            dijit.byId("_documentType_id").attr("required", true);
            dijit.byId("_country_id").attr("required", true);
            dijit.byId("_transactionType_id").attr("required", false);
            dijit.byId("_processingCentre_id").attr("required", false);
            dijit.byId("_productType_id").attr("required", false);
            dijit.byId("_userLocation_id").attr("required", false);
        }
    }
};